package highscore;

// Länk till uppgiften: http://docs.google.com/Doc?id=dc234554_117crcrhzgh

import java.io.File;
import utils.PlayerDoesNotExistException;

// TODO VG+: en metod som tar emot antal och en boolean duplicate
// COMPLETE VG+: en metod som returnerar en viss användares högsta score.

/**
 * Main class. Not used for anything else then to launch the program and debugging
 * @author Duncan Swedman Skomakar'n
 */
public class Main
{
    /**
     * Main method. Launches the program
     * @param args The command line arguments (not used currently)
     */
    public static void main(String[] args)
    {
        /*
        // Adams knark:
        String h = HashMaker.encrypt("Emil Forslund");

        System.out.println(h);
        System.out.println(HashMaker.decrypt(h));*/

        // Emils trams här under:
		Highscore highscore = new Highscore();
		highscore.addItemByScore(new HighscoreRow("Emil Forslund", 1, 99999999));
		highscore.addItemByScore(new HighscoreRow("Patrik", 1, 99999999));
		highscore.addItemByScore(new HighscoreRow("Grönis", 999, -2));
		highscore.addItemByScore(new HighscoreRow("Grönisi", 302, 213332));
		highscore.addItemByScore(new HighscoreRow("Adam", 1337, 9001));
		highscore.addItemByScore(new HighscoreRow("Peder", 1337, 203));
		highscore.addItemByScore(new HighscoreRow("Nisse", 1337, 29));
		highscore.addItemByScore(new HighscoreRow("G0raN^", 1337, 92100));
		highscore.addItemByScore(new HighscoreRow("Baldur", 1337, 8219));
		highscore.addItemByScore(new HighscoreRow("Geirmundur", 1337, 1293));
		highscore.addItemByScore(new HighscoreRow("Eldur", 1337, 2321));
		highscore.addItemByScore(new HighscoreRow("Eldur", 1337, 8219));
		highscore.addItemByScore(new HighscoreRow("Adam", 1337, 8219));
		highscore.addItemByScore(new HighscoreRow("Emil Forslund", 1337, 912));
		highscore.addItemByScore(new HighscoreRow("Patrik", 1337, 21));
		highscore.addItemByScore(new HighscoreRow("Peder", 1337, 2312));
		highscore.addItemByScore(new HighscoreRow("Peder", 1337, 1000));
		HighscorePrinter lol = new HighscorePrinter(highscore);

        // Adam är här och petar:
        HighscoreFileHandler handler = new HighscoreFileHandler(highscore);
        HighscoreOrganizer organizer = new HighscoreOrganizer(highscore);

        handler.saveHighscore("fil.ehs");
        handler.loadHighscore("fil.ehs");
		new File("fil.ehs").delete();

        System.out.println("HIGHSCORE TABLE\n===============");
        organizer.orderByScoreDescending();
        lol.printInOrderSeparated();
        
        System.out.println("\nHIGHSCORE TABLE\n===============");
        lol.printInOrderShared();

		try
		{
			System.out.println("Patrik's best score: " + organizer.getPlayersBestScore("Patrik").getScore());
		}
		catch (PlayerDoesNotExistException ex)
		{
			ex.printStackTrace();
		}

		//Show a window.
		new HighscoreWindow(highscore);
    }
}